package com.klikmee.sms.chat.web.filters;

import java.util.Date;

import com.klikmee.sms.cef.CoreAdapter;
import com.klikmee.sms.chat.web.dao.AnswerDAO;
import com.klikmee.sms.chat.web.dao.QuestionDAO;
import com.klikmee.sms.services.chat.model.Answer;
import com.klikmee.sms.services.chat.model.Question;

public abstract class AbstractFilter implements MessageFilter{

	/**
	 * Instance of core adapter used to send 
	 */
	protected CoreAdapter coreAdapter;
	/**
	 * Ref to the answer dao
	 */
	protected AnswerDAO answerDAO = null;
	/**
	 * Keyword that activates this listener. Listener matches message text in
	 * search for keyword
	 * 
	 */
	protected QuestionDAO questionDAO = null;
	/**
	 * Regular expression which if matched activates this listener.
	 */
	protected String activationExpression = null;

	public AbstractFilter() {
		super();
	}

	/**
	 * Persists {@link Answer} object into database
	 * 
	 * @param question
	 * @param messageText
	 * @param refCoreId
	 * @param visible
	 *            TODO
	 */
	protected void persistAnswer(Question question, String messageText, Long refCoreId, boolean visible) {
		Answer answer = new Answer();
		answer.setAnswer(messageText);
		answer.setCoreID(refCoreId);
		answer.setDateAnswered(new Date());
		answer.setFromNumber(question.getToNumber());
		answer.setQuestion(question);
		answer.setToNumber(question.getFromNumber());
		answer.setVisable(visible);

		this.answerDAO.create(answer);
	}
	
	public void setActivationExpression(String activationExpression) {
		this.activationExpression = activationExpression;
	}

	public void setAnswerDAO(AnswerDAO answerDAO) {
		this.answerDAO = answerDAO;
	}

	public void setQuestionDAO(QuestionDAO questionDAO) {
		this.questionDAO = questionDAO;
	}

	public void setCoreAdapter(CoreAdapter coreAdapter) {
		this.coreAdapter = coreAdapter;
	}

}